// userMock.js
import Mock from "mockjs";


// 管理员账号数据
const adminData = {
    id: "1",
    username: "admin",
    password: "123456",
    role: "admin",
    name: "管理员12138"
};

// 手动定义普通用户数据
const userList = [
    { id: "1", username: "q", password: "1", role: "user", name: "张三" },
    { id: "2", username: "w", password: "1", role: "user", name: "李四" },
    { id: "3", username: "e", password: "1", role: "user", name: "王五" }
];

// 普通用户登录接口
Mock.mock('/api/getUserData', 'post', (aaa) => {
    const { username, password } = JSON.parse(aaa.body);

    // 检查是否为管理员账号
    if (username === adminData.username && password === adminData.password) {
        return {
            code: 1,
            message: '管理员登录成功',
            data: {
                userData: adminData
            }
        };
    }

    // 普通用户验证
    const user = userList.find(user => user.username === username && user.password === password);
    if (user) {
        return {
            code: 1,
            message: '用户登录成功',
            data: { userData: user }
        };
    } else {
        return {
            code: 0,
            message: '用户名或密码错误',
            data: null
        };
    }
});
